//
//  VideoBigViewController.m
//  ToYourHeartNews
//
//  Created by XJing on 16/1/25.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥. All rights reserved.
//

#import "VideoBigViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface VideoBigViewController ()
@property (nonatomic, strong)UIView *playerView;/**< 播放视图 */
@property (nonatomic, strong)AVPlayer *player;/**< 播放器对象 */
@property (nonatomic, strong)AVPlayerLayer *playerLayer;/**< 播放器图层 */
@property (nonatomic, strong)AVPlayerItem *playerItem;/**< 播放对象 */
@end

@implementation VideoBigViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.playerView = [UIView alloc]initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)
    //初始化播放器
    [self createAVPlayer];
}
#pragma mark - 初始化播放器
-(void)createAVPlayer
{
    //视频网址
    NSString *str = _str;
    //统一资源定位符
    NSURL *url = [NSURL URLWithString:str];
    //创建播放对象(playerItem)
    self.playerItem = [AVPlayerItem playerItemWithURL:url];
    //创建播放器(player)
    self.player = [AVPlayer playerWithPlayerItem:_playerItem];
    //创建显示layer(playerLayer) (投影)
    self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
    //layer需要设置大小
    _playerLayer.frame = CGRectMake(10, 5, self.view.bounds.size.width - 10, 250);
    //视频填充模式
    _playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    //将显示的图层 放在页面里显示
    [_playerView.layer insertSublayer:_playerLayer atIndex:0];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
